package com.study.ioc.demo;

import com.study.ioc.demo.bean.TestBeanTwo;
import com.study.ioc.demo.factorybean.MyFactoryBean;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {MyFactoryBean.class})
public class MyFactoryBeanTest {

    @Autowired
    private ApplicationContext applicationContext;

    @Test
    public void test() {
        MyFactoryBean myFactoryBean = applicationContext.getBean(MyFactoryBean.class);
        try {
            TestBeanTwo object = myFactoryBean.getObject();
            System.out.println(object);
            System.out.println(applicationContext.getBean("myFactoryBean"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
